package com.gitee.wsl.time.schedule

import kotlin.time.Instant
import kotlinx.datetime.TimeZone
import kotlin.time.ExperimentalTime

@OptIn(ExperimentalTime::class)
class LambdaScheduler(
    private val onNext:(Instant) -> Instant?
) : AbstractTimeScheduler() {

    override fun next(
        createdAtInstant: Instant,
        currentInstant: Instant,
        zoneId: TimeZone,
    ): Result<Instant> {
        val next = onNext(createdAtInstant)?:return throwCall()
        return Result.success(next)
    }
}

@OptIn(ExperimentalTime::class)
fun Scheduler(
    onNext: (Instant) -> Instant?
) = LambdaScheduler(onNext)
